﻿
#region Using

using System.Runtime.Serialization;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel.DomainServices.Server;
using System;

#endregion Using

namespace NetBay.Core.BusinessEntities.Barcodes
{
    /// <summary>Represent an code bar parameter.</summary>
    [DataContract]
    public class Barcode : ReturnObject
    {
        #region Attributs

        /// <summary>Barcode id.</summary>
        private long _Id;

        /// <summary>Barcode parameter code.</summary>
        private string _ParamCode;

        /// <summary>Barcode name.</summary>
        private string _Name;

        /// <summary>Barcode description.</summary>
        private string _Description;

        /// <summary>Barcode function.</summary>
        private BarcodeSeparatorType _Function;

        /// <summary>Barcode function label.</summary>
        private string _FunctionLabel;

        /// <summary>Barcode status.</summary>
        private bool _Status;

        /// <summary>Barcode type.</summary>
        private BarcodeType _Type;

        /// <summary>Barcode type label.</summary>
        private string _TypeLabel;

        /// <summary>Barcode prefix.</summary>
        private string _Prefix;


        private List<BarcodeSeparator> _barCodeSeparator = new List<BarcodeSeparator>();
        
        #endregion Attributs

        #region Properties

        /// <summary>
        /// Gets or sets the Barcode id.
        /// </summary>
        /// <value>The Barcode id.</value>
        [DataMember]
        public long Identifier
        {
            get { return _Id; }
            set { _Id = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode parameter code.
        /// </summary>
        /// <value>The Barcode parameter code.</value>
        [DataMember]
        public string ParamCode
        {
            get { return _ParamCode; }
            set { _ParamCode = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode name.
        /// </summary>
        /// <value>The Barcode name.</value>
        [DataMember]
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode description.
        /// </summary>
        /// <value>The Barcode description.</value>
        [DataMember]
        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode function.
        /// </summary>
        /// <value>The Barcode function.</value>
        [DataMember]
        public BarcodeSeparatorType Function
        {
            get { return _Function; }
            set { _Function = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode function label.
        /// </summary>
        /// <value>The Barcode function label.</value>
        [DataMember]
        public string FunctionLabel
        {
            get { return _FunctionLabel; }
            set { _FunctionLabel = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode status.
        /// </summary>
        /// <value>The Barcode status.</value>
        [DataMember]
        public bool Enabled
        {
            get { return _Status; }
            set { _Status = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode type.
        /// </summary>
        /// <value>The Barcode type.</value>
        [DataMember]
        public BarcodeType Type
        {            
            get { return _Type; }
            set { _Type = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode type label.
        /// </summary>
        /// <value>The Barcode type label.</value>
        [DataMember]
        public string TypeLabel
        {
            get { return _TypeLabel; }
            set { _TypeLabel = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode prefix.
        /// </summary>
        /// <value>The Barcode prefix.</value>
        [DataMember]
        public string Prefix
        {
            get { return _Prefix; }
            set { _Prefix = value; }
        }

        /// <summary>
        /// Gets or sets the Barcode separator list.
        /// </summary>
        /// <value>The Barcode separator list.</value>
        [Association("BarCodeSeparatorList", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<BarcodeSeparator> BarCodeSeparatorList
        {
            get { return _barCodeSeparator; }
            set
            {
                if (value != null)
                {
                    _barCodeSeparator = value;
                    ItemEntity.SetForeignKey(_barCodeSeparator, Key);
                }
            }
        }

        #endregion Properties                                     

        #region Init/Constructor

        /// <summary>
        /// Default constructor
        /// </summary>
        public Barcode()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Document"/> class for error usages
        /// </summary>
        /// <param name="errorMessage">The error message.</param>
        /// <param name="applicationException">The application exception.</param>
        public Barcode(string errorMessage, Exception applicationException = null)
            : base(errorMessage, applicationException)
        {
        }

        #endregion

    }
}
